package com.example.jurisdiction.Service.impl;

import com.example.jurisdiction.Mapper.MenusMapper;
import com.example.jurisdiction.Service.MenusService;
import entity.Menus;
import entity.Tree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenusServiceImpl implements MenusService {

	@Autowired
	private MenusMapper md;
	
	@Override
	public List<Tree> getQuery() {
		List<Menus> mlist=md.querys();
		List<Tree> tlist=querys(mlist);
		return tlist;
	}
	
	
	public List<Tree> querys(List<Menus> mlist) {
		List<Tree> tlist=new ArrayList<Tree>();
		for (Menus menus : mlist) {
			Tree t=new Tree();
			t.setId(menus.getId());
			t.setLable(menus.getName());
			t.setHref(menus.getLinkUrl());
			List<Menus> mlist1=md.query(menus.getId());
			if(mlist1.size()!=0) {
				List<Tree> tlist1=querys(mlist1);
				t.setChildren(tlist1);
			}
			tlist.add(t);
		}
		return tlist;
	}
	
}
